package com.example.shangjiba;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;

import androidx.appcompat.app.AppCompatActivity;

import com.example.shangjiba.R;

public class InterestSelectActivity extends AppCompatActivity {

    private Button btnBackInterest;
    private Button btnConfirmInterest;
    private CheckBox cbRead;
    private CheckBox cbPhotography;
    private CheckBox cbPingpong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interest_select);

        btnBackInterest = findViewById(R.id.btn_back_interest);
        btnConfirmInterest = findViewById(R.id.btn_confirm_interest);
        cbRead = findViewById(R.id.cb_read);
        cbPhotography = findViewById(R.id.cb_photography);
        cbPingpong = findViewById(R.id.cb_pingpong);

        // 返回按钮：关闭当前页
        btnBackInterest.setOnClickListener(v -> finish());

        // 确定按钮：回传选中的兴趣
        btnConfirmInterest.setOnClickListener(v -> {
            StringBuilder interestBuilder = new StringBuilder();
            // 拼接选中的兴趣
            if (cbRead.isChecked()) interestBuilder.append("阅读");
            if (cbPhotography.isChecked()) {
                if (interestBuilder.length() > 0) interestBuilder.append("、");
                interestBuilder.append("摄影");
            }
            if (cbPingpong.isChecked()) {
                if (interestBuilder.length() > 0) interestBuilder.append("、");
                interestBuilder.append("乒乓球");
            }

            String interest = interestBuilder.toString();
            Intent intent = new Intent();
            intent.putExtra("interest", interest);
            setResult(RESULT_OK, intent); // 设置返回结果
            finish(); // 关闭当前页
        });
    }
}